importPackage(com.blocks.blocks);
importPackage(com.blocks);
importPackage(com.blocks.model);
importPackage(com.jme3.math);
importPackage(java.lang);
importPackage(com.blocks.script);
importPackage(com.jme3.math);
importPackage(com.jme3.collision);
importPackage(com.jme3.scene.debug);
importPackage(com.jme3.scene);
importPackage(com.jme3.material);

var block = new Object(); 
var counter = 0;
var direction = 0;
var FREQUENCY = 0;
var DELAY = 0.1; //Time Per Frame Delay
var BULLET_LIFE = 1; //How long the Bullet will live
block.setup = function(name) {
 	thisBlock.setName("Cannon");
 	thisBlock.setTextureRow(1.0);
	thisBlock.setTextureColumn(9.0);	
 	thisBlock.resetTexture();	
  } 
block.loop = function(name, tpf) { 

	if(thisBlock.isPowered() && thisBlock.getFrequency(thisBlock.getBlockSides()) > FREQUENCY){
		counter = counter + tpf;
		if(counter > DELAY){				
			masterId = java.lang.System.currentTimeMillis();
			var master5 = new com.blocks.blocks.MasterBlock("master5", masterId);
			master5.init();
			var direction = thisBlock.getWorldRotation().getRotationColumn(2);
			master5.setLocalTranslation(thisBlock.getWorldTranslation());
			master5.setDeathTimer(BULLET_LIFE);
			master5.setPowered(false);
			
			master5.updatePower(true);
			com.blocks.ScriptBlocksApplication.getInstance().addMasterBlock(master5.getMasterId(), master5);
			com.blocks.ScriptBlocksApplication.getInstance().getRootNode().attachChild(master5);
			
			var frequency = thisBlock.getFrequency(thisBlock.getBlockSides());
			
			var forceVector = direction.mult(frequency);
			master5.setLocalTranslation(master5.getLocalTranslation().add(forceVector));			
			counter = 0;				
		}
	}
	
 }


block.scriptExport = function() {
	return ("");
} 

